package com.example.backend.mapper;

import com.example.backend.entity.Car;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface CarMapper {


    @Insert("insert into car(user_name,shop_name,dish_name,num,money) values(#{user_name},#{shop_name},#{dish_name},1,#{money})")
    int insert(Car car);

    @Delete("delete from car where car_num=#{car_num}")
    int delete(String car_num);

    @Update("update car set car_num=#{car_num},user_name=#{user_name},shop_name=#{shop_name},dish_name=#{dish_name},num=#{num},money=#{money} where car_num=#{car_num}")
    int update(Car car);

    @Select("select * from car where car_num=#{car_num}")
    ArrayList<Car>queryAll(String car_num);

    @Select("select * from car where id= #{id}")
    ArrayList<Car> selectById(Integer id);

    @Update("update car set num=num+1,money=money+#{money} where user_name= #{user_name} and shop_name= #{shop_name} and dish_name= #{dish_name}")
    int updateAdd(Car car);

    @Update("update car set num=num-1,money=money-#{money} where user_name= #{user_name} and shop_name= #{shop_name} and dish_name= #{dish_name}")
    int updateJian(Car car);

    @Select("select count(*) from car where user_name= #{user_name} and shop_name= #{shop_name} and dish_name= #{dish_name} ")
    int selectExist(Car car);

    @Select("select * from car where user_name= #{user_name} and shop_name= #{shop_name} and num>0")
    ArrayList<Car> selectCars(Car car);

    @Update("update car set num=0,money=0.0  where user_name= #{user_name} and shop_name= #{shop_name}")
    int updateShopNum(Car car);
}
